import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react'
import {resolve} from 'path'
import { createStyleImportPlugin, AntdResolve } from 'vite-plugin-style-import'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    react(),
    // 自动打包antd组件对应的样式配置1
    createStyleImportPlugin({
      resolves: [AntdResolve()]
    })
  ],
  // 自动打包antd组件对应的样式配置2
  css: {
    preprocessorOptions: {
      less: {
        javascriptEnabled: true,
        modifyVars: {
          '@primary-color': '#1DA57A',//设置antd主题色
        },
      },
    }
  },
  resolve: {
    extensions: ['.js', '.jsx', '.ts', '.tsx'],
    alias: {
      '@': resolve(__dirname, './src'),
      '@api': resolve(__dirname, './src/api'),
      '@comps': resolve(__dirname, './src/components'),
      '@pages': resolve(__dirname, './src/pages'),
    },
  },
  server: {
    proxy: {
      // 将来以/app-dev开头的请求，就会被开发服务器转发到目标服务器去。
      '/app-dev': {
        // 需要转发的请求前缀
        target: 'http://syt-api.atguigu.cn', // 目标服务器地址
        changeOrigin: true, // 允许跨域
        rewrite: (path) => path.replace(/^\/app-dev/, ''),
      },
    },
  },
});
